package com.calvin.tingapp.extsdk;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import com.calvin.tingapp.MainActivity;
import com.tencent.connect.UserInfo;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

public class TencentSdk implements IUiListener {
    static final String APP_ID = "1104558267";
    static final String APP_KEY = "OQdQzLBp1gB6AHe6";
    private static TencentSdk mInstance = null;

    Tencent mTencent = null;

    public static TencentSdk shared() {
        return mInstance == null ? (mInstance = new TencentSdk()) : mInstance;
    }

    private TencentSdk() {
        mTencent = Tencent.createInstance(APP_ID, MainActivity.sharedCurrent().getApplicationContext());

    }

    public void login(Activity activity) {
        if (!mTencent.isSessionValid()) {
            mTencent.login(activity, "get_user_info", this);
        }
    }

    @Override
    public void onComplete(Object o) {
        Log.i("debug", "onComplate:" + mTencent.getOpenId() + "x" + mTencent.getAccessToken());
        UserInfo userInfo = new UserInfo(MainActivity.sharedCurrent(), mTencent.getQQToken());
        userInfo.getUserInfo(new IUiListener() {
            @Override
            public void onComplete(Object o) {
                Log.i("debug", "" + o);
            }

            @Override
            public void onError(UiError uiError) {

            }

            @Override
            public void onCancel() {

            }
        });
    }

    @Override
    public void onError(UiError uiError) {

        Log.i("debug", "onError:" + uiError);
    }

    @Override
    public void onCancel() {

        Log.i("debug", "onCancel");
    }
}
